package com.yunzo.coc;

import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.yunzo.coc.config.Context;
import com.yunzo.coc.handle.ContextHandler;
import com.yunzo.coc.interceptor.ErrorInterceptor;
import com.yunzo.coc.model.*;
import com.yunzo.coc.router.APIRouter;
import com.yunzo.coc.handle.APINotFoundHandler;
import com.yunzo.coc.router.ActionRouter;

/**
 * JFinal总配置文件，挂接所有接口与插件
 * @author xiaobo
 */
public class AppConfig extends JFinalConfig {

    /**
     * 常量配置
     */
	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);//开启开发模式
		me.setEncoding("UTF-8");
        me.setViewType(ViewType.JSP);
	}

    /**
     * 所有接口配置
     */
	@Override
	public void configRoute(Routes me) {
		me.add(new APIRouter());//接口路由
        me.add(new ActionRouter()); //页面路由
	}

    /**
     * 插件配置
     */
	@Override
	public void configPlugin(Plugins me) {
		C3p0Plugin cp = new C3p0Plugin(loadPropertyFile("jdbc.properties"));
		
		me.add(cp);
        
//        //初始化连接池插件
//        loadPropertyFile("jdbc.properties");
//        HikariCPPlugin hcp = new HikariCPPlugin(getProperty("jdbcUrl"), 
//                getProperty("user"), 
//                getProperty("password"), 
//                getProperty("driverClass"), 
//                getPropertyToInt("maxPoolSize"),
//                getPropertyToInt("minPoolSize"));
//        
//        me.add(hcp);
        
        ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
        //arp.setShowSql(true);
		me.add(arp);
        //基础平台信息
        arp.addMapping("y_basic_applogin", BasicApploginModel.ID, BasicApploginModel.class);//app用户登陆记录表
        arp.addMapping("pt_department", BasicDepartmentModel.ID, BasicDepartmentModel.class);//基础平台部门表
        arp.addMapping("pt_dict", BasicDictModel.ID, BasicDictModel.class);//基础平台字典表
        arp.addMapping("pt_menu", BasicMenusModel.ID, BasicMenusModel.class);//基础平台菜单表
        arp.addMapping("pt_module", BasicModuleModel.ID, BasicModuleModel.class);//基础平台模块表
        arp.addMapping("pt_operator", BasicOperatorModel.ID, BasicOperatorModel.class);//基础平台功能表
        arp.addMapping("pt_param", BasicParamModel.ID, BasicParamModel.class);//基础平台参数表
        arp.addMapping("y_basic_personnel", BasicPersonnelModel.ID, BasicPersonnelModel.class);//基础平台职员表
        arp.addMapping("pt_role", BasicRoleModel.ID, BasicRoleModel.class);//基础平台角色表
        arp.addMapping("y_basic_smsauthcode", BasicSmsauthcodeModel.ID, BasicSmsauthcodeModel.class);//基础平台短信验证码表
        arp.addMapping("y_basic_smssendinfo", BasicSmssendinfoModel.ID, BasicSmssendinfoModel.class);//基础平台短信发送记录表
        arp.addMapping("pt_station", BasicStationModel.ID, BasicStationModel.class);//基础平台岗位（职位）表
        arp.addMapping("y_basic_sysbugs", BasicSysbugsModel.ID, BasicSysbugsModel.class);//基础平台BUG表
        arp.addMapping("pt_syslog", BasicSyslogModel.ID, BasicSyslogModel.class);//基础平台日志表
        arp.addMapping("pt_systems", BasicSystemsModel.ID, BasicSystemsModel.class);//基础平台系统表
        arp.addMapping("pt_upload", BasicUploadModel.ID, BasicUploadModel.class);//基础平台文件上传表
        arp.addMapping("pt_userinfo", BasicUserinfoModel.ID, BasicUserinfoModel.class);//基础平台用户详细信息表
        arp.addMapping("pt_user", BasicUserModel.ID, BasicUserModel.class);//基础平台用户表
        arp.addMapping("pt_group", BasicUsersgroupModel.ID, BasicUsersgroupModel.class);//基础平台用户分组表
        
        arp.addMapping("y_basic_area", BasicAreainfoModel.ID, BasicAreainfoModel.class);//区县
        arp.addMapping("y_basic_province", BasicProvincerModel.ID, BasicProvincerModel.class);//省
        arp.addMapping("y_basic_city", BasicCityModel.ID, BasicCityModel.class);//城市
        arp.addMapping("y_basic_trade", BasicTradeModel.ID, BasicTradeModel.class);//行业
        
        //团体信息
        arp.addMapping("y_group_appinfo", GroupAppinfoModel.ID, GroupAppinfoModel.class);//团体APP信息记录表
        arp.addMapping("y_group_businessinfo_browse", GroupBusinessinfoBrowseModel.ID, GroupBusinessinfoBrowseModel.class);//团体商机信息浏览记录表
        arp.addMapping("y_group_businessinfo", GroupBusinessinfoModel.ID, GroupBusinessinfoModel.class);//团体商机信息表
        arp.addMapping("y_group_contacts", GroupContactsModel.ID, GroupContactsModel.class);//团体通讯录记录表
        arp.addMapping("y_group_dynamicinfo", GroupDynamicinfoModel.ID, GroupDynamicinfoModel.class);//团体动态信息表
        arp.addMapping("y_group_ecprodinfo", GroupEcprodinfoModel.ID, GroupEcprodinfoModel.class);//团体电商信息表
        arp.addMapping("y_group_ecprod_order", GroupEcprodOrderModel.ID, GroupEcprodOrderModel.class);//团体电商订单表
        arp.addMapping("y_group_ecprodtypeinfo", GroupEcprodtypeinfoModel.ID, GroupEcprodtypeinfoModel.class);//团体电商分类表
        arp.addMapping("y_group_info", GroupInfoModel.ID, GroupInfoModel.class);//团体信息表
        arp.addMapping("y_group_informinfo", GroupInforminfoModel.ID, GroupInforminfoModel.class);//团体通知信息表
        arp.addMapping("y_group_inform_join", GroupInformJoinModel.ID, GroupInformJoinModel.class);//团体通知参加记录表
        arp.addMapping("y_group_integral", GroupIntegralModel.ID, GroupIntegralModel.class);//团体记分表
        arp.addMapping("y_group_joinusentry", GroupJoinusentryModel.ID, GroupJoinusentryModel.class);//团体申请加入记录表
        arp.addMapping("y_group_member_caddress", GroupMemberCaddressModel.ID, GroupMemberCaddressModel.class);//团体会员收货地址信息表
        arp.addMapping("y_group_member_company", GroupMemberCompanyModel.ID, GroupMemberCompanyModel.class);//团体会员公司信息表
        arp.addMapping("y_group_member_concern", GroupMemberConcernModel.ID, GroupMemberConcernModel.class);//团体会员关注记录表
        arp.addMapping("y_group_member_feedback", GroupMemberFeedbackModel.ID, GroupMemberFeedbackModel.class);//团体会员反馈信息表
        arp.addMapping("y_group_member_inbox", GroupMemberInboxModel.ID, GroupMemberInboxModel.class);//团体会员私信表
        arp.addMapping("y_group_member_inbox_reply", GroupMemberInboxReplyModel.ID, GroupMemberInboxReplyModel.class);//团体会员私信回复表
        arp.addMapping("y_group_memberinfo", GroupMemberinfoModel.ID, GroupMemberinfoModel.class);//团体会员详细信息表
        arp.addMapping("y_group_member_label", GroupMemberLabelModel.ID, GroupMemberLabelModel.class);//团体会员自定义标签信息表
        arp.addMapping("y_group_member", GroupMemberModel.ID, GroupMemberModel.class);//团体会员基础信息表
        arp.addMapping("y_group_member_showtime", GroupMemberShowtimeModel.ID, GroupMemberShowtimeModel.class);//团体会员炫信息表
        arp.addMapping("y_group_member_systemsms", GroupMemberSystemsmsModel.ID, GroupMemberSystemsmsModel.class);//团体会员系统消息记录表
        //公用 系统级
        arp.addMapping("y_system_adinfo", SystemAdinfoModel.ID, SystemAdinfoModel.class);//系统广告信息表
        arp.addMapping("y_system_collect", SystemCollectModel.ID, SystemCollectModel.class);//系统收藏信息表
        arp.addMapping("y_system_pointlike", SystemPointlikeModel.ID, SystemPointlikeModel.class);//系统表态信息表
        arp.addMapping("y_system_review", SystemReviewModel.ID, SystemReviewModel.class);//系统评论信息表
        arp.addMapping("y_system_review_reply", SystemReviewReplyModel.ID, SystemReviewReplyModel.class);//系统评论回复表
        
        arp.addMapping("y_group_inform_browse", GroupInformBrowse.ID, GroupInformBrowse.class);//团体通知浏览记录表
        arp.addMapping("y_group_member_showtime_browse", GroupMShowBrowseModel.ID, GroupMShowBrowseModel.class);//团体炫浏览记录表
        
        //新增表信息 20160408 请求新增好友
        arp.addMapping("y_group_member_friends", GroupMShowBrowseModel.ID, GroupMemberModelFriends.class);
        arp.addMapping("y_group_member_friends_sms", GroupMemberModelFriendsSms.ID, GroupMemberModelFriendsSms.class);
        //推送记录
        arp.addMapping("y_system_jpush_urlinfo", SystemJpushUrlInfoModel.ID, SystemJpushUrlInfoModel.class);
        arp.addMapping("y_system_jpush_usrreadinfo", SystemJpushUserReadInfoModel.ID, SystemJpushUserReadInfoModel.class);
        
        arp.addMapping("form_actiavy", BasicFormActioyModel.ID, BasicFormActioyModel.class);//团体炫浏览记录表
        
        //原系统数据转换
        arp.addMapping("y_basic_socialgroups", OLDGroup.ID, OLDGroup.class);//团体表
        
        
	}

    /**
     * 拦截器配置
     */
	@Override
	public void configInterceptor(Interceptors me) {
		me.add(new ErrorInterceptor());
		
	}

    /**
     * handle 配置*
     */
	@Override
	public void configHandler(Handlers me) {
        me.add(new ContextHandler());
		me.add(new APINotFoundHandler());
	}

    @Override
    public void afterJFinalStart() {
        Context.me().init();
    }

    @Override
    public void beforeJFinalStop() {
        Context.me().destroy();
    }
}